/**
 * @author madStone_l
 */
Ext.define('Sys.ux.GridPanelRowEditor', {
			extend : 'Sys.ux.GridPanel',
			alias : 'widget.sysgridpanelroweditor',
			requires : ['Ext.grid.plugin.RowEditing'],
			config : {
				editor : null,
				showAddBtn : true,
				showEditBtn : true,
				showRefreshBtn : true,
				showDelBtn : true,
				showTbar : true,
				defaultValues : {}
				// 新增操作时默认值
			},
			constructor : function(config) {
				if (config.showTbar !== false) {
					if (Ext.isEmpty(config.showRefreshBtn))
						config.showRefreshBtn = true;
					if (Ext.isEmpty(config.showDelBtn))
						config.showDelBtn = true;
					config.tbar = config.tbar || [];
					config.showAddBtn !== false && config.tbar.push({
								text : '新增',
								iconCls : 'icon_add',
								handler : function(btn) {
									var g = btn.up('grid');
									g.editor.cancelEdit();
									var r = Ext.ModelManager
											.create(g.defaultValues, g
															.getStore().model);
									g.getStore().insert(0, r);
									g.getView().refresh();
									g.editor.startEdit(0, 0);
								}
							});
					config.showEditBtn !== false && config.tbar.push({
								text : '修改',
								iconCls : 'icon_edit',
								handler : function(btn) {
									var g = btn.up('grid');
									var s = g.checkSelect(true);
									if (!s)
										return false;
									g.editor.startEdit(g.getStore().indexOf(s),
											0);
								}
							});
					config.tbarItems && config.tbar.push('-', config.tbarItems);
				}

				config.plugins = config.plugins || [];
				var sign = true;
				Ext.each(config.plugins, function(v, i, a) {
							if (v.$className == 'Ext.grid.plugin.RowEditing') {
								sign = false;
								return sign;
							}
						});
				if (sign) {
					this.setEditor(Ext.create('Ext.grid.plugin.RowEditing', {
								errorSummary : false,
								autoCancel : false
							}));
					// this.editor = Ext.create('Ext.grid.plugin.RowEditing', {
					// errorSummary : false,
					// autoCancel : false
					// });
					config.plugins.push(this.getEditor());
					this.getEditor().on('canceledit',
							function(editor, e, eOpts) {
								var s = e.grid.getStore();
								if (Ext.isEmpty(e.record.get(s.idProperty))) {
									s.remove(e.record);
									e.grid.getView().refresh();
								}
							});
					this.getEditor().on('edit', function(editor, e) {
								alert('完成编辑');
							});

				}

				this.callParent(arguments);
			},

			statics : {
				method : function() {
					return 'abc';
				}
			}
		});